package com.qianyanglong.m3u8.listner;

import com.qianyanglong.m3u8.frame.HomeFrame;
import com.qianyanglong.m3u8.model.M3U8TableModel;
import com.qianyanglong.m3u8.table.M3U8Table;

import javax.swing.*;
import javax.swing.table.TableColumnModel;
import java.awt.*;
import java.awt.event.*;

public class HomeComponentListener implements ComponentListener,WindowStateListener,WindowListener {

    private M3U8Table m3U8Table;

    private JScrollPane scrollPane;

    public HomeComponentListener(M3U8Table m3U8Table, JScrollPane scrollPane){
        this.m3U8Table = m3U8Table;
        this.scrollPane = scrollPane;
    }

    @Override
    public void componentResized(ComponentEvent e) {
        HomeFrame homeFrame = (HomeFrame)e.getComponent();
        int width = homeFrame.getWidth();
        int height = homeFrame.getHeight();
        this.scrollPane.setSize(width-40,height-60);
        this.m3U8Table.setPreferredScrollableViewportSize(m3U8Table.getParent().getSize());
        this.m3U8Table.revalidate();
    }

    @Override
    public void componentMoved(ComponentEvent e) {

    }

    @Override
    public void componentShown(ComponentEvent e) {

    }

    @Override
    public void componentHidden(ComponentEvent e) {

    }

    @Override
    public void windowStateChanged(WindowEvent e) {
        System.out.println("状态变化");
        int oldState = e.getOldState();
        int newState = e.getNewState();
        HomeFrame homeFrame = (HomeFrame)e.getComponent();
        int width = homeFrame.getWidth();
        int height = homeFrame.getHeight();
        this.scrollPane.setSize(width-40,height-60);

    }

    @Override
    public void windowOpened(WindowEvent e) {

    }

    @Override
    public void windowClosing(WindowEvent e) {

    }

    @Override
    public void windowClosed(WindowEvent e) {

    }

    @Override
    public void windowIconified(WindowEvent e) {

    }

    @Override
    public void windowDeiconified(WindowEvent e) {

    }

    @Override
    public void windowActivated(WindowEvent e) {
        HomeFrame homeFrame = (HomeFrame)e.getComponent();
        int width = homeFrame.getWidth();
        int height = homeFrame.getHeight();
        this.scrollPane.setSize(width-40,height-60);
    }

    @Override
    public void windowDeactivated(WindowEvent e) {

    }
}
